/* 同余 中国剩余定理(CRT)
* 1.拓展欧几里得算法
    (a,b) = d;
    ax0 + by0 = d

    x = x0 + k(a/d)
    y = y0 - k(b/d)

    ax = 1(mod b)

    ax = (b, a mod b)

* 2.欧拉定理
    1ex = 1 (mod c)
    -> a^(phi(n)) = 1 (mod n) && (a,n)互质
        且满足上述式子的最小正整数x一定是phi(c)的约数，即x|phi(c)

* 3.中国剩余定理(CRT)
    1.对于数字 W[i]，求出（即相乘）其他所有数字的最小公倍数M;
    2.在M所有整数倍中，找到一个模B[i]为1的数字N[i];
    3.对所有N[i]求和，不断对所有W[i]的最小公倍数取模;
    4.最后剩下的一个不能减的正数即为所求。
    x = a1 (mod m1)
    x = a2 (mod m2)
    ......
    x = an (mod mn)
    设M = m1m2m3...mn
    令Mi = M/mi ti是关于M的逆元 Mi*ti = 1 (mod M)

    x = 累加(1~n) aiMiti

    

* 本题:
    中国剩余定理的应用
*/

#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define int long long
const int N = 10;
int n;
int A[N], B[N];

int exgcd(int a, int b, int &x, int &y) //ax+by = gcd(a,b) x,y是整数
{
    if(!b) //此时 gcd(a,0) = a -> ax+by=gcd(a,b) -> x=0,y=1
    {
        x = 1, y = 0;
        return a;
    }

    int d = exgcd(b, a%b, y, x); //gcd(b, a % b) bx' + (a % b)y' = gcd(b, a % b) 
     y -= a / b * x; // x = y'，y = x' - (a / b) * y'
    return d;
}

//龟速乘
int qmul(int base1, int base2, int MOD) //base1 * base2
{
    int res = 0;
    while(base2) {
        if(base2 & 1) res = (res + base1) % MOD;
        base1 = (base1 + base1) % MOD;
        base2 >>= 1;
    }
    return res;
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> n;
    int M = 1;
    for(int i = 0; i < n; i++) {
        cin >> A[i] >> B[i]; // x%A[i] = B[i]
        M *= A[i];  //最小公倍数,但A互质
    }

    int res = 0;
    for(int i = 0; i < n; i++) {
        int Mi = M / A[i]; //A[i]逆元
        int ti, x;
        exgcd(Mi, A[i], ti, x);
        int d =  qmul(Mi, B[i], M);
        d = qmul(ti, d, M);
        // int d = ti*(Mi*B[i] - M)% M; //防爆方法2 Mi*B[i]-M=Mi*B[i] (mod M) 
        // d = (d+M) % M; //上一行可能取负
        res = (res + d) % M; //B[i]*Mi*ti
    }
    cout << (res+M)%M << endl;
    return 0;
} //999510067897128